#define __STDC_VERSION__ 201112L
#include<stdio.h>
#include<time.h>
#include<unistd.h>
#include<stdlib.h>
#include "process.h"

typedef void (*flush_t)(double total,double cur);

const int base = 100;
double total = 2048.0;
double once = 0.1;

//进度条的调用
void download(flush_t f) 
{
  double current = 0.0;
  while(current < total)
  {
    //模拟下载行为
    int r = rand() % base + 1;//[1 , 100]
    double speed = r * once;
    current += speed;
    if(current >= speed)
    {
      current = total;
    }
    usleep(10000);

    f(total,current);
  }
  printf("\n");
}

int main()
{
  srand(time(NULL));

  download(FulshProcess);
  download(FulshProcess);
  download(FulshProcess);
  return 0;
}
